package com.hadoop.sort;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.io.WritableUtils;

public class DateKey implements WritableComparable<DateKey>{

	//복합키 
	private String year;
	private Integer month;

	public DateKey(){
		
	}
	
	public DateKey(String year, Integer date){
		this.year = year;
		this.month = date;
	}
	
	public String getYear() {
		return year;
	}

	public void setYear(String year) {
		this.year = year;
	}

	public Integer getMonth() {
		return month;
	}

	public void setMonth(Integer month) {
		this.month = month;
	}
	
	@Override
	public String toString(){
		return (new StringBuilder()).append(year).append(",").append(month).toString();
	}
	
	@Override
	public void readFields(DataInput arg0) throws IOException {
		year = WritableUtils.readString(arg0);
		month = arg0.readInt();
		
	}

	@Override
	public void write(DataOutput arg0) throws IOException {
		WritableUtils.writeString(arg0, year);
		arg0.writeInt(month);
		
	}

	@Override
	public int compareTo(DateKey o) {
		int result = year.compareTo(o.year);
		if(0 == result){
			result = month.compareTo(o.month);
		}
		
		return result;
	}

}
